Skip to content

Conversation

you06
Copy link
Contributor

@you06 you06 commented Jul 25, 2025

First-time contributors' checklist

What is changed, added or deleted? (Required)

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions (in Chinese).

  • master (the latest development version)
  • v9.0 (TiDB 9.0 versions)
  • v8.5 (TiDB 8.5 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)
  • v6.1 (TiDB 6.1 versions)
  • v5.4 (TiDB 5.4 versions)

What is the related PR or file link(s)?

  • This PR is translated from:
  • Other reference link(s):

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

@ti-chi-bot ti-chi-bot bot added missing-translation-status This PR does not have translation status info. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 25, 2025
follower-read.md Outdated
Follower Read 功能适用于以下场景:

- 希望通过 follower 打散读热点。
- 希望通过读取本地副本节省流量。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个“本地”是否展开解释成 “相同 zone tidb 访问 tikv“?

通过读取本地副本节省流量的使用场景推荐的设置为:

- 默认值 `leader` 的性能最好。
- `closest-adaptive` 在最小性能损失的前提下尽可能节省流量。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @joey-yez
这个 adaptive 是否也归到不推荐使用,只保留 closest-replica 和默认 leader

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议保留这个 adaptive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closest-adaptive 是推荐使用的配置,对自己的 workload 不够了解的情况可以先用这个。

follower-read.md Outdated
### Follower 副本选择策略

由于 TiKV 的 Follower Read 不会破坏 TiDB 的 Snapshot Isolation 事务隔离级别,因此 TiDB 选择 follower 的策略可以采用 round robin 的方式。目前,对于 Coprocessor 请求,Follower Read 负载均衡策略粒度是连接级别的,对于一个 TiDB 的客户端连接在某个具体的 Region 上会固定使用同一个 follower,只有在选中的 follower 发生故障或者因调度策略发生调整的情况下才会进行切换。而对于非 Coprocessor 请求(点查等),Follower Read 负载均衡策略粒度是事务级别的,对于一个 TiDB 的事务在某个具体的 Region 上会固定使用同一个 follower,同样在 follower 发生故障或者因调度策略发生调整的情况下才会进行切换。如果同一事务内既有点查请求又有 Coprocessor 请求,两种请求都将按照上述调度策略分别进行读取,即使 Coprocessor 和点查出现在同一个 Region 上,TiDB 也会当作独立事件来处理。
由于 TiKV 的 Follower Read 不会破坏 TiDB 的 Snapshot Isolation 事务隔离级别,因此 TiDB 会根据 `tidb_replica_read` 选择满足要求的副本进行读取。当选中的 follower 节点出现无法访问的故障或其他错误时,会切换到 leader 提供服务。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否提一下这里的策略是第一轮请求处理,不包含后续内部 region error 处理和重试?

@ti-chi-bot ti-chi-bot bot requested a review from joey-yez July 29, 2025 09:43
Signed-off-by: you06 <[email protected]>
@qiancai qiancai added v9.0-beta.3 This PR/issue applies to TiDB v9.0-beta.3. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. translation/doing This PR’s assignee is translating this PR. for-release This PR relates to a TiDB release but does not have a tracked feature. and removed missing-translation-status This PR does not have translation status info. labels Sep 4, 2025
follower-read.md Outdated
- 当一个读请求的预估返回结果小于变量 [`tidb_adaptive_closest_read_threshold`](/system-variables.md#tidb_adaptive_closest_read_threshold-从-v630-版本开始引入) 的值时,TiDB 会选择 leader 副本执行读取操作。

- 当设置为 `learner` 时,TiDB 会选择 learner 副本执行读取操作。在读取时,如果当前 Region 没有 learner 副本,TiDB 会报错
- 当设置为 `learner` 时,TiDB 会选择 learner 副本执行读取操作。在读取时,如果当前 Region 没有 learner 副本,TiDB 会从 leader 读取数据
Copy link
Member

@lilin90 lilin90 Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看到 @zyguan 的一个 PR #20609 里是这么更新的,请 @you06 看下按哪个表述:

当设置为 learner 时,TiDB 会选择 learner 副本执行读取操作。在读取时,如果当前 Region 没有 learner 副本或 learner 副本不可用,TiDB 会从可用 leader 或 follower 副本读取数据。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#20609 的描述更加准确,可以先把 #20609 合并,我再把这个 PR 修改一下吗

@qiancai qiancai assigned qiancai and unassigned lilin90 Oct 16, 2025
@qiancai
Copy link
Collaborator

qiancai commented Oct 16, 2025

/bot-review

Copy link

✅ AI review completed, 15 comments generated.

@pingcap pingcap deleted a comment from github-actions bot Oct 16, 2025
@pingcap pingcap deleted a comment from github-actions bot Oct 16, 2025
@pingcap pingcap deleted a comment from github-actions bot Oct 16, 2025
@pingcap pingcap deleted a comment from github-actions bot Oct 16, 2025
@pingcap pingcap deleted a comment from github-actions bot Oct 16, 2025
@pingcap pingcap deleted a comment from github-actions bot Oct 16, 2025
@pingcap pingcap deleted a comment from github-actions bot Oct 16, 2025
@pingcap pingcap deleted a comment from github-actions bot Oct 16, 2025
Copy link

ti-chi-bot bot commented Oct 16, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from qiancai. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

## 基本监控

通过观察相关监控,可以帮助判断是否需要使用 Follower Read 和打开 Follower Read 之后的效果。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个小节没有写去哪里观察哪个监控指标,可以判断是否需要使用 Follower Read 以及开启 Follower Read 后的效果。

Copy link
Collaborator

@qiancai qiancai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Oct 16, 2025
Copy link

ti-chi-bot bot commented Oct 16, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-10-16 04:14:26.84471498 +0000 UTC m=+326772.921967539: ☑️ agreed by qiancai.

qiancai and others added 2 commits October 16, 2025 12:17
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@qiancai qiancai force-pushed the follower-read-update branch from 7f74bb3 to 1aa4bb7 Compare October 16, 2025 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

for-release This PR relates to a TiDB release but does not have a tracked feature. needs-1-more-lgtm Indicates a PR needs 1 more LGTM. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. translation/doing This PR’s assignee is translating this PR. v9.0-beta.3 This PR/issue applies to TiDB v9.0-beta.3.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants